#!/usr/bin/perl -w


my $file = shift;

if(!$file) {
  print("Error: filename expected as first argument. Aborting...\n");
  exit();
}

my $ring_size = $file;

$ring_size =~ s/^.*_(\d+)n.*$/$1/g;
#print("ring size: ".$ring_size."\n");

my %multicasts = ();
my %handlers = ();

open(FILE, $file);

while(<FILE>) {
  $line = $_;
  if($line =~ m/LOG_RECEIVE_MULTICAST/) {
    $line =~ s/^.*\s*.*'(\d+)'.*$/$1/g;

    chomp($line);  
    if($line =~ m/\d+/) {
        $multicasts{$line} = $line;
    }
  }
  elsif($line =~ m/LOG_MESSAGE_HANDLER/) {
    $line =~ s/^.*\s*.*'(\d+)'.*$/$1/g;

    chomp($line);  
    if($line =~ m/\d+/) {
        $handlers{$line} = $line;
    }
  }
}

close(FILE);


#while((my $key, my $value) = each(%multicasts)) {
#  print($key."\n");
#}

#while((my $key, my $value) = each(%handlers)) {
#  print($key."\n");
#}

my $nodes_in_tree = keys(%multicasts);
my $group_members = keys(%handlers);
my $raw_forwarders = keys(%multicasts) - keys(%handlers);

#print("number of nodes in tree: ".$nodes_in_tree."\n");
#print("number of group members: ".$group_members."\n");
#print("number of raw forwarders: ".$raw_forwarders."\n");

print($ring_size."\t".$nodes_in_tree."\t".$group_members."\t".$raw_forwarders."\n");